﻿<UserControl x:Class="Waf.MusicManager.Presentation.Views.TranscodingListView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:p="clr-namespace:Waf.MusicManager.Presentation.Properties"
             xmlns:ctrl="clr-namespace:Waf.MusicManager.Presentation.Controls"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:dd="clr-namespace:Waf.MusicManager.Presentation.DesignData"
             mc:Ignorable="d" d:DataContext="{d:DesignInstance dd:SampleTranscodingListViewModel, IsDesignTimeCreatable=True}"
             d:DesignHeight="500" d:DesignWidth="300" Background="{StaticResource DefaultBackground}">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <ListBox x:Name="transcodingListBox" ItemsSource="{Binding TranscodingManager.TranscodeItems}" SelectionMode="Extended" HorizontalContentAlignment="Stretch"
                 BorderThickness="0" Background="{StaticResource DefaultBackground}" AllowDrop="True"
                 ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                 ctrl:SelectionBehavior.SyncSelectedItems="{Binding SelectedTranscodeItems}">
            <ListBox.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <Border BorderBrush="LightGray" BorderThickness="0,0,0,1" Margin="0,0,0,2" SnapsToDevicePixels="True">
                                <TextBlock Text="{Binding Name, Converter={StaticResource TranscodeStatusToStringConverter}}" FontWeight="SemiBold" Margin="5,3,5,3"/>
                            </Border>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                </GroupStyle>
            </ListBox.GroupStyle>
            
            <ListBox.ItemContainerStyle>
                <Style TargetType="ListBoxItem" BasedOn="{StaticResource {x:Type ListBoxItem}}">
                    <Setter Property="Padding" Value="0,3,4,12"/>
                    <Setter Property="AllowDrop" Value="True"/>
                    <Setter Property="ContextMenu">
                        <Setter.Value>
                            <ContextMenu>
                                <MenuItem Command="{Binding TranscodingService.CancelSelectedCommand}" Header="{x:Static p:Resources.CancelSelection}"/>
                            </ContextMenu>
                        </Setter.Value>
                    </Setter>
                    <EventSetter Event="ContextMenuOpening" Handler="ListBoxItemContextMenuOpening"/>
                </Style>
            </ListBox.ItemContainerStyle>
            
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="6"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="65"/>
                            <ColumnDefinition Width="3"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="1"/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition Height="2"/>
                        </Grid.RowDefinitions>

                        <TextBlock Text="{Binding Source.Metadata.Artists, Converter={StaticResource StringListToStringConverter}, ConverterParameter=ListSeparator}" 
                                   FontWeight="SemiBold" TextTrimming="CharacterEllipsis" Grid.Row="1" Grid.Column="1" ctrl:ToolTipBehavior.AutoToolTip="True"/>
                        <TextBlock TextTrimming="CharacterEllipsis" Grid.Row="2" Grid.Column="1" ctrl:ToolTipBehavior.AutoToolTip="True">
                            <TextBlock.Text>
                                <MultiBinding Converter="{StaticResource MusicTitleConverter}">
                                    <Binding Path="Source.FileName"/>
                                    <Binding Path="Source.Metadata.Artists"/>
                                    <Binding Path="Source.Metadata.Title"/>
                                </MultiBinding>
                            </TextBlock.Text>
                        </TextBlock>

                        <TextBlock Text="{Binding Source.Metadata.Bitrate, Converter={StaticResource BitrateConverter}}" 
                                   HorizontalAlignment="Right" Grid.Row="1" Grid.Column="2"/>
                        <TextBlock Text="{Binding Source.Metadata.Duration, Converter={StaticResource DurationConverter}}" 
                                   HorizontalAlignment="Right" Grid.Row="2" Grid.Column="2"/>

                        <ProgressBar Grid.Row="3" Grid.Column="1" VerticalAlignment="Center" Margin="0,2,5,0" 
                                     Maximum="1">
                            <ProgressBar.Style>
                                <Style TargetType="ProgressBar" BasedOn="{StaticResource {x:Type ProgressBar}}">
                                    <Setter Property="Foreground" Value="{StaticResource ErrorForeground}"/>
                                    <Setter Property="Value" Value="1"/>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Error}" Value="{x:Null}">
                                            <Setter Property="Foreground" Value="{StaticResource ActiveForeground}"/>
                                            <Setter Property="Value" Value="{Binding Progress}"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </ProgressBar.Style>
                        </ProgressBar>
                        <TextBlock Text="{Binding Progress, StringFormat=#0 %}" Grid.Row="3" Grid.Column="2"  HorizontalAlignment="Right"
                                   Visibility="{Binding Error, Converter={StaticResource NullToVisibilityConverter}, ConverterParameter=invert}"/>
                        <TextBlock Text="{x:Static p:Resources.Error}" Grid.Row="3" Grid.Column="2" TextAlignment="Right" FontWeight="SemiBold" Foreground="{StaticResource ErrorForeground}"
                                   Visibility="{Binding Error, Converter={StaticResource NullToVisibilityConverter}}">
                            <TextBlock.ToolTip>
                                <ctrl:SuperToolTip Title="{x:Static p:Resources.InternalErrorDescription}" Description="{Binding Error.Message}"/>
                            </TextBlock.ToolTip>
                        </TextBlock>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <Button x:Name="statusBarButton" Click="StatusBarButtonClick" Content="&#xE10C;" Grid.Row="1"
                Height="21" Background="{StaticResource DarkBackground}" BorderThickness="0" 
                FontFamily="Segoe UI Symbol" FontSize="10" HorizontalContentAlignment="Center"/>
        <ctrl:Flyout x:Name="menuPopup" PlacementTarget="{Binding ElementName=statusBarButton}" Placement="Top">
            <Border BorderBrush="White" BorderThickness="0,1" Background="{StaticResource DarkBackground}">
                <Grid Margin="5,10,5,5">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="80"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <Button Command="{Binding TranscodingService.CancelAllCommand}" Content="&#xE10A;" Style="{StaticResource IconButtonStyle}" Grid.Row="0" Grid.Column="0"/>
                    <TextBlock Text="{x:Static p:Resources.CancelAll}" Style="{StaticResource AppBarTextBlockStyle}" Grid.Row="1" Grid.Column="0"/>
                </Grid>
            </Border>
        </ctrl:Flyout>
    </Grid>
</UserControl>
